package cn.tedu.cake.service.impl;

import cn.tedu.cake.ex.ServiceException;
import cn.tedu.cake.mapper.CategoryMapper;
import cn.tedu.cake.mapper.ShoppingMapper;
import cn.tedu.cake.pojo.dto.CategoryDTO;
import cn.tedu.cake.pojo.dto.ShoppingDTO;
import cn.tedu.cake.pojo.entity.Category;
import cn.tedu.cake.pojo.entity.Shopping;
import cn.tedu.cake.service.ICategoryService;
import cn.tedu.cake.service.ShoppingService;
import cn.tedu.cake.web.ServiceCode;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ShoppingServiceImpl implements ShoppingService {
    @Autowired
    private ShoppingMapper shoppingMapper;

    @Override
    public void addNew(ShoppingDTO shoppingDTO){
       Shopping shopping=new Shopping();
       BeanUtils.copyProperties(shoppingDTO,shopping);
       shoppingMapper.insert(shopping);
    }

    @Override
    public void deleteById(int id){
        int c = shoppingMapper.deleteById(id);
        if (c==0){
            String message = "删除失败,ID不存在!";
            throw new ServiceException(ServiceCode.ERR_NOT_FOUND,message);
        }
    }

    @Override
    public void update(Shopping shopping){
        int c = shoppingMapper.update(shopping);
    }
}
